package com.magic.gre.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.magic.gre.R;
import com.magic.gre.entity.ActivityBean;
import com.noname.lib_base_java.adapter.CommonAdapter;
import com.noname.lib_base_java.adapter.ViewHolder;
import com.noname.lib_base_java.glide.LoadImageUtils;
import com.noname.lib_base_java.util.PathUtil;
import com.noname.lib_base_java.util.TimeUtils;

import java.util.List;

/**
 * Author: Lmoumou
 * Date: 2019-01-09 18:15
 * 文件名: ActivityAdapter
 * 描述:
 */
public class ActivityAdapter extends CommonAdapter<ActivityBean> {

    public OnActivityitemListener onActivityitemListener;
    private boolean isSelf;

    public void setOnActivityitemListener(OnActivityitemListener onActivityitemListener) {
        this.onActivityitemListener = onActivityitemListener;
    }

    public ActivityAdapter(Context mContext, List<ActivityBean> mData, boolean isSelf) {
        super(mContext, mData, R.layout.item_activity);
        this.isSelf = isSelf;
    }

    @Override
    protected void bindData(ViewHolder holder, int position) {
        final ActivityBean bean = mData.get(position);
        ImageView coverIv = holder.getView(R.id.cover_iv);
        LoadImageUtils.loadImage(PathUtil.imgPath(bean.getCoverImage()), coverIv);
        holder.setText(R.id.name_tv, bean.getTitle());
        holder.setText(R.id.intrduce_tv, bean.getPlainContent());
        holder.setText(R.id.time_tv, TimeUtils.long2String(bean.getStartTime(), "yyyy.MM.dd"));
        holder.getView(R.id.mButton).setVisibility(isSelf ? View.GONE : bean.getType() == 1 ? View.VISIBLE : View.GONE);
//        holder.getView(R.id.mButton).setVisibility(bean.getType()==1?View.VISIBLE:View.GONE);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onActivityitemListener != null) {
                    onActivityitemListener.onItemClick(bean.getDataUrl(), bean.getId());
                }
            }
        });
        holder.getView(R.id.mButton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onActivityitemListener != null) {
                    onActivityitemListener.onSignUp(bean);
                }
            }
        });
    }

    public interface OnActivityitemListener {
        void onItemClick(String url, String activityId);

        void onSignUp(ActivityBean bean);
    }
}
